//PITCH PROGRAM
//CLASS: TEAM
//		-methods to calculate scores for team
//		and store scores in vector
//BY: ALEX TRACY
import java.util.Vector;
public class Team 
{

	private Vector<Integer> taken = new Vector<Integer>();
	private Vector<Integer> scoresArray = new Vector<Integer>();
	private int score = 0;
	private int bid;
	private int index;
	
	public Team(int i)
	{
		index = i;
	}
	
	//add taken cards array to vector taken
	public void addTaken(int cards[])
	{
		for(int i = 0 ; i < cards.length ; i++)
			taken.add(cards[i]);
	}//end addTaken
	
	//Score Functions//

	//return scores array
	public Vector<Integer> getScores()
	{
		return scoresArray;
	}//end getScores
	
	//set teams high bid
	public void setBid(int i)
	{
		bid = i;
	}//end setBid
	
	//set team index
	public void setIndex(int i)
	{
		index = i;
	}//End setIndex
	
	//get highest trump
	public int getHigh(int trump)
	{
		int temp = -1;
		for (int i = 0; i < taken.size() ; i++ )
		{
			if (Card.getSuit(taken.get(i)) == trump 
					&& taken.get(i) > temp)
				temp = taken.get(i);
		}
		return temp;
	}//end getHigh
	
	//get lowest trump
	public int getLow(int trump)
	{
		int temp = 53;
		for (int i = 0; i < taken.size() ; i++ )
		{
			if (Card.getSuit(taken.get(i)) == trump 
					&& taken.get(i) < temp)
				temp = taken.get(i);
		}
		return temp;
	}//end getLow
	
	//check if team took jack if team did
	//then add a point to score
	public void checkForJack(int trump)
	{
		for (int i = 0; i < taken.size() ; i++ )
		{
			if ( Card.getSuit(taken.get(i)) == trump 
					&& (Card.isJack(taken.get(i)) ) )
				{
				addToScore();
				break;
				}
		}	
		
	}//End checkForJack
	
	//calculate game and return it
	public int getGame()
	{
		int game = 0;
		for (int i = 0 ; i < taken.size() ; i++)
		{
			if ( ( taken.get(i) % 13 )== 8) //10
				game = game + 10;
			else if ( ( taken.get(i) % 13 ) == 9) //Jack
				game = game + 1;
			else if ( ( taken.get(i) % 13 )== 10)//Queen
				game = game + 2;
			else if ( ( taken.get(i) % 13 ) == 11)//King
				game = game + 3;
			else if ( ( taken.get(i) % 13 ) == 12)//Ace
				game = game + 4;
		}
		return game;
	}//end calcGame()
	
	//add 1 point to score
	public void addToScore()
	{
		score++;
	}
	
	//return the current score
	public int getCurrentScore()
	{
		return scoresArray.get(scoresArray.size() - 1);
	}
	
	//clear the taken array
	public void clearTaken()
	{
		taken.clear();
	}
	//calculate score if bid was made add points
	//otherwise subtract them
	public void calcScore(int trump)
	{
		this.checkForJack(trump);
		if (score >= bid)
		{
			if (scoresArray.isEmpty())
				scoresArray.add(score);
			else
				scoresArray.add(getCurrentScore() + score);
		}
		else
		{
			if (scoresArray.isEmpty())
				scoresArray.add(-(bid));
			else
				scoresArray.add(getCurrentScore() - bid);
		}
		
		score = 0;
	}
	
	
}
